//
//  ProfileViewController.m
//  phonebook
//
//  Created by akamasam on 10/1/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ProfileViewController.h"
#import "ProfileEditingViewController.h"
#import "RecordManager.h"


@implementation ProfileViewController

@synthesize phone;
@synthesize address;
@synthesize picture;
@synthesize person;
@synthesize row_P;
@synthesize phone_lable;
@synthesize address_lable;
@synthesize editProfile;
@synthesize deleteProfile;

/*- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Configure the cell.
    
    int row=indexPath.row;
    NSDictionary *name=[names objectAtIndex:row];
    
    NSString *nameName=[name objectForKey:@"name"];
    //NSString *nameName=[name objectForKey:@"name"];
    cell.textLabel.text=nameName;
    return cell;
}


-(void) loadaddress:(NSString*) path{
    NSString *textString=[NSString stringWithContentsOfFile:path
                                                   encoding:NSUTF8StringEncoding
                                                      error:NULL];
    self.resultTextView.text=textString;
    
}*/

- (IBAction)editButtonPressed {
    
    ProfileEditingViewController *detailViewController = [[ProfileEditingViewController alloc] initWithNibName:@"ProfileEditingViewController" bundle:nil];
    // ...
    // Pass the selected object to the new view controller.
    detailViewController.row_PP = row_P;
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    [detailViewController release];
}

-(IBAction)dialButtonPressed{
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://PhoneNumber"]];
    
}




- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [person autorelease];
    [phone_lable autorelease];
    [address_lable autorelease];
    [super dealloc];
    
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
//    Names=[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"names" ofType:@"plist"]];
//    [Names retain];
    
    Names = [[RecordManager sharedManager] names];
    
    //int row_PP=row_P.text;
    NSDictionary *name=[Names objectAtIndex:row_P];
    
    NSString *NameName=[name objectForKey:@"name"];
    NSString *PhoneNumber=[name objectForKey:@"phone number"];
    NSString *Address=[name objectForKey:@"note"];
    NSString *ImageV=[name objectForKey:@"imageview"];
    
    
    
    self.picture.image=[UIImage imageNamed:ImageV];
    
    self.person.text=NameName;
    self.phone_lable.text=PhoneNumber;
    self.address_lable.text=Address;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
